package cn.tyoui.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.tyoui.bean.UserBean;

@Controller
public class HomeController {

	@RequestMapping("/index")
	public String login(HttpServletRequest request) {
		System.out.println("11111111");
		HttpSession session = request.getSession();
		UserBean user = (UserBean) session.getAttribute("user");
		System.out.println("user : " + user);
		if(user == null) {
			return "login";
		}
		if(user.getUserName().equals("admin") && user.getPassWord().equals("amdin")) {
			return "home";
		}else {
			return "login";
		}
	}
	@RequestMapping("/home")
	public String home(HttpServletRequest request) {
		System.out.println("22222");
		HttpSession session = request.getSession();
		UserBean user = (UserBean) session.getAttribute("user");
		System.out.println("user : " + user);
		if(user == null) {
			System.out.println("1");
			return "login";
		}
		System.out.println(user.getUserName().equals("admin"));
		System.out.println(user.getPassWord().equals("admin"));
		System.out.println(user.getPassWord());
		if(user.getUserName().equals("admin") && user.getPassWord().equals("admin")) {
			System.out.println("2");
			return "home";
		}else {
			System.out.println("3");
			return "login";
		}
	}
}
